<?php
class View_Message_View extends View_Message
{
	/**
	 *	...
	 *	@access		public
	 *	@return		string
	 */
	public function buildContent()
	{
		$words		= $this->words['message']['view'];
		$current	= $this->auth->getCurrentUser();

		if( $messageId	= $this->request->get( 'messageId' ) )
		{
			$message	= Logic_Message::getMessage( $messageId );
			$sender		= Logic_User::getUserData( $message['source'] );
			if( $message['source'] == $current )
				$sender		= Logic_User::getUserData( $message['target'] );

			$formData	= array(
				'source'	=> $sender['username'],
				'timestamp'	=> date( $config['layout.format.timestamp'], $message['timestamp'] ),
				'status'	=> $this->words['message']['states'][$message['status']],
				'subject'	=> $message['subject'],
				'body'		=> $this->includeBugLink( nl2br( $message['body'] ) ),
			);

			$ui	= array(
				'words'		=> $words,
				'form'		=> $this->buildForm(
					'message',
					'viewMessage',
					'message',
					'view',
					$formData
				),
				'buttonCancel'	=> $this->html->LinkButton(
					self::getUrl(),
					$words['buttonCancel'],
					'but cancel'
				),
				'buttonRemove'	=> $this->html->Button(
					'removeMessage',
					$words['buttonRemove'],
					'but remove',
					$words['buttonRemoveConfirm']
				),
				'buttonReply'	=> UI_HTML_Elements::LinkButton(
					self::getUrl( array( 'messageId' => $messageId, 'action' => 'reply' ) ),
					$words['buttonReply'],
					'but edit'
				),
				'buttonForward'	=> UI_HTML_Elements::LinkButton(
					self::getUrl( array( 'messageId' => $messageId, 'action' => 'forward' ) ),
					$words['buttonForward'],
					'but edit'
				),

				'form.tag'			=> $this->html->Form(
					'sendMessage',
					self::getUrl( array( 'messageId' => $this->request->get( 'messageId' ) ) )
				),
				'colgroup'		=> $this->html->ColumnGroup( "25%", "75%" ),
				'caption'		=> $this->html->TableCaption( $words['caption'] ),
			);

			if( $current == $message['source'] )													// user wrote message
				unset( $ui['buttonReply'] );														// no reply button
			else if( $message['status'] == 0 )														// received and new
				Logic_Message::setStatus( $messageId, 1 );											// not new anymore

			return $this->loadTemplate( 'message.view', $ui );
		}
	}
}
?>